<html>
<body>
<h1>Calculator</h1>
<form method="get">
	Equation: <input type="text" name="equation" />
			  <input type="submit" value="Calculate" />
</form>

<?php
	if(isset($_GET["equation"])&&$_GET["equation"]!="")
	{
		echo "<h2>Result:</h2>";
		$input = str_replace('\s','',$_GET["equation"]);
		$pattern = "/[a-zA-Z]|[\+\*\/]{2,}|\-{2,}|\.{2,}|\s\.|\.(\s)*\d|[\+\-\*\/][\.\s]*$|^[\*\/\+]|[^0-9\.\+\-\*\/\s]/";
		if (preg_match($pattern,$input))
		{
			echo "Invalid expression $input";
		}
		else if (preg_match("/\/0/",$input)){echo "$input =";}
		else
		{
			eval("\$result = $input;");
			echo "$input = $result";
		}
	}
	else if(isset($_GET["equation"])&&$_GET["equation"]=="")
		echo "Enter Something";
	
?>

</body>
</html>